from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

from kharlia import _engine

__all__ = [
    'actor',
    'base',
    'client'
    'game',
    'level',
    'world'
    ]

#print('NATIVE ENGINE ATTRS:')
#for i in dir(_engine):
#    print(' ', i)

def _PatchClasses():
    '''Make patches to some native classes'''
    
    # FTileset
    def IterTiles(self):
        get = self.GetTileInfoByIndex
        for index in xrange(self.TileCount):
            yield get(index)
            
    _engine.FTileset.IterTiles = IterTiles

    # FResourceManager
    def __iter__(self):
        return self.MakeIter(self)

    _engine.FResourceManager.__iter__ = __iter__

    # FResourceIter
    def __iter__(self):
        return self

    _engine.FResourceManagerIterator.__iter__ = __iter__

    # FResource
    def __str__(self):
        return '<{} \'{}\'>'.format(type(self).__name__, self.Name)

    def __cmp__(self, other):
        return cmp(self.InnerID, other.InnerID)

    def __hash__(self):
        return self.InnerID

    _engine.FResource.__str__ = __str__
    _engine.FResource.__repr__ = __str__
    _engine.FResource.__cmp__ = __cmp__
    _engine.FResource.__hash__ = __hash__

    # FSpriteFrame
    def __getinitargs__(self):
        return ()

    def __getstate__(self):
        return (self.Rect, self.Time)

    def __setstate__(self, state):
        self.Rect = state[0]
        self.Time = state[1]

    _engine.FSpriteFrame.__getinitargs__ = __getinitargs__
    _engine.FSpriteFrame.__getstate__ = __getstate__
    _engine.FSpriteFrame.__setstate__ = __setstate__
    
_PatchClasses()